package org.bugjail.servlet.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bugjail.data.Project;
import org.bugjail.data.TestReport;
import org.bugjail.dataaccess.DAOFactory;
import org.bugjail.dataaccess.objects.TestReportDAO;
import org.bugjail.servlet.BasicServlet;

/**
 * Servlet implementation class for Servlet: NewTestReportServlet
 *
 */
 public class NewTestReportServlet extends BasicServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public NewTestReportServlet() {
		super();
	}   	

	@Override
	protected void action(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int projectid = Integer.parseInt(request.getParameter("projectid"));
		Project p = DAOFactory.getDAOFactory().getProjectDAO().retrieveById(projectid);
		
		TestReportDAO dao = DAOFactory.getDAOFactory().getTestReportDAO();
		TestReport td = new TestReport();
		td.setName(request.getParameter("name"));
		td.setDescription(request.getParameter("description"));
		td.setProject(p);
		dao.create(td);
		response.sendRedirect("TestReportServlet?project="+projectid);
	}

	@Override
	protected void beforeAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}   	  	    
}